﻿///////////////////////////////////////////////////////////////
// This is generated code. 
//////////////////////////////////////////////////////////////
// Code is generated using LLBLGen Pro version: 2.6
// Code is generated on: 2011年7月5日 11:37:43
// Code is generated using templates: SD.TemplateBindings.SharedTemplates.NET20
// Templates vendor: Solutions Design.
// Templates version: 
//////////////////////////////////////////////////////////////
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections;
#if !CF
using System.Runtime.Serialization;
#endif
using System.Data;
using System.Xml.Serialization;
using CARMSData;
using CARMSData.FactoryClasses;
using CARMSData.DaoClasses;
using CARMSData.RelationClasses;
using CARMSData.HelperClasses;
using CARMSData.CollectionClasses;

using SD.LLBLGen.Pro.ORMSupportClasses;

namespace CARMSData.EntityClasses
{
	
	// __LLBLGENPRO_USER_CODE_REGION_START AdditionalNamespaces
	// __LLBLGENPRO_USER_CODE_REGION_END

	/// <summary>
	/// Entity class which represents the entity 'Template'. <br/><br/>
	/// 
	/// </summary>
	[Serializable]
	public partial class TemplateEntity : CommonEntityBase, ISerializable
		// __LLBLGENPRO_USER_CODE_REGION_START AdditionalInterfaces
		// __LLBLGENPRO_USER_CODE_REGION_END	
	{
		#region Class Member Declarations
		private CARMSData.CollectionClasses.MessageCollection	_message;
		private bool	_alwaysFetchMessage, _alreadyFetchedMessage;
		private CARMSData.CollectionClasses.ReportCategoryToTemplateCollection	_reportCategoryToTemplate;
		private bool	_alwaysFetchReportCategoryToTemplate, _alreadyFetchedReportCategoryToTemplate;
		private CARMSData.CollectionClasses.TemplateToReportCategoryCollection	_templateToReportCategory;
		private bool	_alwaysFetchTemplateToReportCategory, _alreadyFetchedTemplateToReportCategory;
		private CARMSData.CollectionClasses.ReportCategoryCollection _reportCategoryCollectionViaReportCategoryToTemplate;
		private bool	_alwaysFetchReportCategoryCollectionViaReportCategoryToTemplate, _alreadyFetchedReportCategoryCollectionViaReportCategoryToTemplate;
		private CARMSData.CollectionClasses.ReportCategoryCollection _reportCategoryCollectionViaTemplateToReportCategory;
		private bool	_alwaysFetchReportCategoryCollectionViaTemplateToReportCategory, _alreadyFetchedReportCategoryCollectionViaTemplateToReportCategory;
		private CARMSData.CollectionClasses.ReportHeaderCollection _reportHeaderCollectionViaMessage;
		private bool	_alwaysFetchReportHeaderCollectionViaMessage, _alreadyFetchedReportHeaderCollectionViaMessage;
		private CARMSData.CollectionClasses.UserCollection _userCollectionViaMessage;
		private bool	_alwaysFetchUserCollectionViaMessage, _alreadyFetchedUserCollectionViaMessage;
		private ActionEntity _action;
		private bool	_alwaysFetchAction, _alreadyFetchedAction, _actionReturnsNewIfNotFound;

		
		// __LLBLGENPRO_USER_CODE_REGION_START PrivateMembers
		// __LLBLGENPRO_USER_CODE_REGION_END
		#endregion

		#region Statics
		private static Dictionary<string, string>	_customProperties;
		private static Dictionary<string, Dictionary<string, string>>	_fieldsCustomProperties;

		/// <summary>All names of fields mapped onto a relation. Usable for in-memory filtering</summary>
		public static partial class MemberNames
		{
			/// <summary>Member name Action</summary>
			public static readonly string Action = "Action";
			/// <summary>Member name Message</summary>
			public static readonly string Message = "Message";
			/// <summary>Member name ReportCategoryToTemplate</summary>
			public static readonly string ReportCategoryToTemplate = "ReportCategoryToTemplate";
			/// <summary>Member name TemplateToReportCategory</summary>
			public static readonly string TemplateToReportCategory = "TemplateToReportCategory";
			/// <summary>Member name ReportCategoryCollectionViaReportCategoryToTemplate</summary>
			public static readonly string ReportCategoryCollectionViaReportCategoryToTemplate = "ReportCategoryCollectionViaReportCategoryToTemplate";
			/// <summary>Member name ReportCategoryCollectionViaTemplateToReportCategory</summary>
			public static readonly string ReportCategoryCollectionViaTemplateToReportCategory = "ReportCategoryCollectionViaTemplateToReportCategory";
			/// <summary>Member name ReportHeaderCollectionViaMessage</summary>
			public static readonly string ReportHeaderCollectionViaMessage = "ReportHeaderCollectionViaMessage";
			/// <summary>Member name UserCollectionViaMessage</summary>
			public static readonly string UserCollectionViaMessage = "UserCollectionViaMessage";

		}
		#endregion
		
		/// <summary>Static CTor for setting up custom property hashtables. Is executed before the first instance of this entity class or derived classes is constructed. </summary>
		static TemplateEntity()
		{
			SetupCustomPropertyHashtables();
		}

		/// <summary>CTor</summary>
		public TemplateEntity()
		{
			InitClassEmpty(null);
		}


		/// <summary>CTor</summary>
		/// <param name="templateId">PK value for Template which data should be fetched into this Template object</param>
		public TemplateEntity(System.Int32 templateId)
		{
			InitClassFetch(templateId, null, null);
		}

		/// <summary>CTor</summary>
		/// <param name="templateId">PK value for Template which data should be fetched into this Template object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		public TemplateEntity(System.Int32 templateId, IPrefetchPath prefetchPathToUse)
		{
			InitClassFetch(templateId, null, prefetchPathToUse);
		}

		/// <summary>CTor</summary>
		/// <param name="templateId">PK value for Template which data should be fetched into this Template object</param>
		/// <param name="validator">The custom validator object for this TemplateEntity</param>
		public TemplateEntity(System.Int32 templateId, IValidator validator)
		{
			InitClassFetch(templateId, validator, null);
		}


		/// <summary>Private CTor for deserialization</summary>
		/// <param name="info"></param>
		/// <param name="context"></param>
		protected TemplateEntity(SerializationInfo info, StreamingContext context) : base(info, context)
		{
			_message = (CARMSData.CollectionClasses.MessageCollection)info.GetValue("_message", typeof(CARMSData.CollectionClasses.MessageCollection));
			_alwaysFetchMessage = info.GetBoolean("_alwaysFetchMessage");
			_alreadyFetchedMessage = info.GetBoolean("_alreadyFetchedMessage");
			_reportCategoryToTemplate = (CARMSData.CollectionClasses.ReportCategoryToTemplateCollection)info.GetValue("_reportCategoryToTemplate", typeof(CARMSData.CollectionClasses.ReportCategoryToTemplateCollection));
			_alwaysFetchReportCategoryToTemplate = info.GetBoolean("_alwaysFetchReportCategoryToTemplate");
			_alreadyFetchedReportCategoryToTemplate = info.GetBoolean("_alreadyFetchedReportCategoryToTemplate");
			_templateToReportCategory = (CARMSData.CollectionClasses.TemplateToReportCategoryCollection)info.GetValue("_templateToReportCategory", typeof(CARMSData.CollectionClasses.TemplateToReportCategoryCollection));
			_alwaysFetchTemplateToReportCategory = info.GetBoolean("_alwaysFetchTemplateToReportCategory");
			_alreadyFetchedTemplateToReportCategory = info.GetBoolean("_alreadyFetchedTemplateToReportCategory");
			_reportCategoryCollectionViaReportCategoryToTemplate = (CARMSData.CollectionClasses.ReportCategoryCollection)info.GetValue("_reportCategoryCollectionViaReportCategoryToTemplate", typeof(CARMSData.CollectionClasses.ReportCategoryCollection));
			_alwaysFetchReportCategoryCollectionViaReportCategoryToTemplate = info.GetBoolean("_alwaysFetchReportCategoryCollectionViaReportCategoryToTemplate");
			_alreadyFetchedReportCategoryCollectionViaReportCategoryToTemplate = info.GetBoolean("_alreadyFetchedReportCategoryCollectionViaReportCategoryToTemplate");
			_reportCategoryCollectionViaTemplateToReportCategory = (CARMSData.CollectionClasses.ReportCategoryCollection)info.GetValue("_reportCategoryCollectionViaTemplateToReportCategory", typeof(CARMSData.CollectionClasses.ReportCategoryCollection));
			_alwaysFetchReportCategoryCollectionViaTemplateToReportCategory = info.GetBoolean("_alwaysFetchReportCategoryCollectionViaTemplateToReportCategory");
			_alreadyFetchedReportCategoryCollectionViaTemplateToReportCategory = info.GetBoolean("_alreadyFetchedReportCategoryCollectionViaTemplateToReportCategory");
			_reportHeaderCollectionViaMessage = (CARMSData.CollectionClasses.ReportHeaderCollection)info.GetValue("_reportHeaderCollectionViaMessage", typeof(CARMSData.CollectionClasses.ReportHeaderCollection));
			_alwaysFetchReportHeaderCollectionViaMessage = info.GetBoolean("_alwaysFetchReportHeaderCollectionViaMessage");
			_alreadyFetchedReportHeaderCollectionViaMessage = info.GetBoolean("_alreadyFetchedReportHeaderCollectionViaMessage");
			_userCollectionViaMessage = (CARMSData.CollectionClasses.UserCollection)info.GetValue("_userCollectionViaMessage", typeof(CARMSData.CollectionClasses.UserCollection));
			_alwaysFetchUserCollectionViaMessage = info.GetBoolean("_alwaysFetchUserCollectionViaMessage");
			_alreadyFetchedUserCollectionViaMessage = info.GetBoolean("_alreadyFetchedUserCollectionViaMessage");
			_action = (ActionEntity)info.GetValue("_action", typeof(ActionEntity));
			if(_action!=null)
			{
				_action.AfterSave+=new EventHandler(OnEntityAfterSave);
			}
			_actionReturnsNewIfNotFound = info.GetBoolean("_actionReturnsNewIfNotFound");
			_alwaysFetchAction = info.GetBoolean("_alwaysFetchAction");
			_alreadyFetchedAction = info.GetBoolean("_alreadyFetchedAction");

			base.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance());
			
			// __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
			// __LLBLGENPRO_USER_CODE_REGION_END
		}

		
		/// <summary>Performs the desync setup when an FK field has been changed. The entity referenced based on the FK field will be dereferenced and sync info will be removed.</summary>
		/// <param name="fieldIndex">The fieldindex.</param>
		protected override void PerformDesyncSetupFKFieldChange(int fieldIndex)
		{
			switch((TemplateFieldIndex)fieldIndex)
			{
				case TemplateFieldIndex.ShowActionId:
					DesetupSyncAction(true, false);
					_alreadyFetchedAction = false;
					break;
				default:
					base.PerformDesyncSetupFKFieldChange(fieldIndex);
					break;
			}
		}
		
		/// <summary>Gets the inheritance info provider instance of the project this entity instance is located in. </summary>
		/// <returns>ready to use inheritance info provider instance.</returns>
		protected override IInheritanceInfoProvider GetInheritanceInfoProvider()
		{
			return InheritanceInfoProviderSingleton.GetInstance();
		}
		
		/// <summary> Will perform post-ReadXml actions</summary>
		protected override void PostReadXmlFixups()
		{
			_alreadyFetchedMessage = (_message.Count > 0);
			_alreadyFetchedReportCategoryToTemplate = (_reportCategoryToTemplate.Count > 0);
			_alreadyFetchedTemplateToReportCategory = (_templateToReportCategory.Count > 0);
			_alreadyFetchedReportCategoryCollectionViaReportCategoryToTemplate = (_reportCategoryCollectionViaReportCategoryToTemplate.Count > 0);
			_alreadyFetchedReportCategoryCollectionViaTemplateToReportCategory = (_reportCategoryCollectionViaTemplateToReportCategory.Count > 0);
			_alreadyFetchedReportHeaderCollectionViaMessage = (_reportHeaderCollectionViaMessage.Count > 0);
			_alreadyFetchedUserCollectionViaMessage = (_userCollectionViaMessage.Count > 0);
			_alreadyFetchedAction = (_action != null);

		}
				
		/// <summary>Gets the relation objects which represent the relation the fieldName specified is mapped on. </summary>
		/// <param name="fieldName">Name of the field mapped onto the relation of which the relation objects have to be obtained.</param>
		/// <returns>RelationCollection with relation object(s) which represent the relation the field is maped on</returns>
		public override RelationCollection GetRelationsForFieldOfType(string fieldName)
		{
			return TemplateEntity.GetRelationsForField(fieldName);
		}

		/// <summary>Gets the relation objects which represent the relation the fieldName specified is mapped on. </summary>
		/// <param name="fieldName">Name of the field mapped onto the relation of which the relation objects have to be obtained.</param>
		/// <returns>RelationCollection with relation object(s) which represent the relation the field is maped on</returns>
		public static RelationCollection GetRelationsForField(string fieldName)
		{
			RelationCollection toReturn = new RelationCollection();
			switch(fieldName)
			{
				case "Action":
					toReturn.Add(TemplateEntity.Relations.ActionEntityUsingShowActionId);
					break;
				case "Message":
					toReturn.Add(TemplateEntity.Relations.MessageEntityUsingTemplateId);
					break;
				case "ReportCategoryToTemplate":
					toReturn.Add(TemplateEntity.Relations.ReportCategoryToTemplateEntityUsingTemplateId);
					break;
				case "TemplateToReportCategory":
					toReturn.Add(TemplateEntity.Relations.TemplateToReportCategoryEntityUsingTemplateId);
					break;
				case "ReportCategoryCollectionViaReportCategoryToTemplate":
					toReturn.Add(TemplateEntity.Relations.ReportCategoryToTemplateEntityUsingTemplateId, "TemplateEntity__", "ReportCategoryToTemplate_", JoinHint.None);
					toReturn.Add(ReportCategoryToTemplateEntity.Relations.ReportCategoryEntityUsingReportCategoryId, "ReportCategoryToTemplate_", string.Empty, JoinHint.None);
					break;
				case "ReportCategoryCollectionViaTemplateToReportCategory":
					toReturn.Add(TemplateEntity.Relations.TemplateToReportCategoryEntityUsingTemplateId, "TemplateEntity__", "TemplateToReportCategory_", JoinHint.None);
					toReturn.Add(TemplateToReportCategoryEntity.Relations.ReportCategoryEntityUsingReportCategoryId, "TemplateToReportCategory_", string.Empty, JoinHint.None);
					break;
				case "ReportHeaderCollectionViaMessage":
					toReturn.Add(TemplateEntity.Relations.MessageEntityUsingTemplateId, "TemplateEntity__", "Message_", JoinHint.None);
					toReturn.Add(MessageEntity.Relations.ReportHeaderEntityUsingReportHeaderId, "Message_", string.Empty, JoinHint.None);
					break;
				case "UserCollectionViaMessage":
					toReturn.Add(TemplateEntity.Relations.MessageEntityUsingTemplateId, "TemplateEntity__", "Message_", JoinHint.None);
					toReturn.Add(MessageEntity.Relations.UserEntityUsingTargetUserId, "Message_", string.Empty, JoinHint.None);
					break;

				default:

					break;				
			}
			return toReturn;
		}



		/// <summary> ISerializable member. Does custom serialization so event handlers do not get serialized.
		/// Serializes members of this entity class and uses the base class' implementation to serialize the rest.</summary>
		/// <param name="info"></param>
		/// <param name="context"></param>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			info.AddValue("_message", (!this.MarkedForDeletion?_message:null));
			info.AddValue("_alwaysFetchMessage", _alwaysFetchMessage);
			info.AddValue("_alreadyFetchedMessage", _alreadyFetchedMessage);
			info.AddValue("_reportCategoryToTemplate", (!this.MarkedForDeletion?_reportCategoryToTemplate:null));
			info.AddValue("_alwaysFetchReportCategoryToTemplate", _alwaysFetchReportCategoryToTemplate);
			info.AddValue("_alreadyFetchedReportCategoryToTemplate", _alreadyFetchedReportCategoryToTemplate);
			info.AddValue("_templateToReportCategory", (!this.MarkedForDeletion?_templateToReportCategory:null));
			info.AddValue("_alwaysFetchTemplateToReportCategory", _alwaysFetchTemplateToReportCategory);
			info.AddValue("_alreadyFetchedTemplateToReportCategory", _alreadyFetchedTemplateToReportCategory);
			info.AddValue("_reportCategoryCollectionViaReportCategoryToTemplate", (!this.MarkedForDeletion?_reportCategoryCollectionViaReportCategoryToTemplate:null));
			info.AddValue("_alwaysFetchReportCategoryCollectionViaReportCategoryToTemplate", _alwaysFetchReportCategoryCollectionViaReportCategoryToTemplate);
			info.AddValue("_alreadyFetchedReportCategoryCollectionViaReportCategoryToTemplate", _alreadyFetchedReportCategoryCollectionViaReportCategoryToTemplate);
			info.AddValue("_reportCategoryCollectionViaTemplateToReportCategory", (!this.MarkedForDeletion?_reportCategoryCollectionViaTemplateToReportCategory:null));
			info.AddValue("_alwaysFetchReportCategoryCollectionViaTemplateToReportCategory", _alwaysFetchReportCategoryCollectionViaTemplateToReportCategory);
			info.AddValue("_alreadyFetchedReportCategoryCollectionViaTemplateToReportCategory", _alreadyFetchedReportCategoryCollectionViaTemplateToReportCategory);
			info.AddValue("_reportHeaderCollectionViaMessage", (!this.MarkedForDeletion?_reportHeaderCollectionViaMessage:null));
			info.AddValue("_alwaysFetchReportHeaderCollectionViaMessage", _alwaysFetchReportHeaderCollectionViaMessage);
			info.AddValue("_alreadyFetchedReportHeaderCollectionViaMessage", _alreadyFetchedReportHeaderCollectionViaMessage);
			info.AddValue("_userCollectionViaMessage", (!this.MarkedForDeletion?_userCollectionViaMessage:null));
			info.AddValue("_alwaysFetchUserCollectionViaMessage", _alwaysFetchUserCollectionViaMessage);
			info.AddValue("_alreadyFetchedUserCollectionViaMessage", _alreadyFetchedUserCollectionViaMessage);
			info.AddValue("_action", (!this.MarkedForDeletion?_action:null));
			info.AddValue("_actionReturnsNewIfNotFound", _actionReturnsNewIfNotFound);
			info.AddValue("_alwaysFetchAction", _alwaysFetchAction);
			info.AddValue("_alreadyFetchedAction", _alreadyFetchedAction);

			
			// __LLBLGENPRO_USER_CODE_REGION_START GetObjectInfo
			// __LLBLGENPRO_USER_CODE_REGION_END
			base.GetObjectData(info, context);
		}
		
		/// <summary> Sets the related entity property to the entity specified. If the property is a collection, it will add the entity specified to that collection.</summary>
		/// <param name="propertyName">Name of the property.</param>
		/// <param name="entity">Entity to set as an related entity</param>
		/// <remarks>Used by prefetch path logic.</remarks>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override void SetRelatedEntityProperty(string propertyName, IEntity entity)
		{
			switch(propertyName)
			{
				case "Action":
					_alreadyFetchedAction = true;
					this.Action = (ActionEntity)entity;
					break;
				case "Message":
					_alreadyFetchedMessage = true;
					if(entity!=null)
					{
						this.Message.Add((MessageEntity)entity);
					}
					break;
				case "ReportCategoryToTemplate":
					_alreadyFetchedReportCategoryToTemplate = true;
					if(entity!=null)
					{
						this.ReportCategoryToTemplate.Add((ReportCategoryToTemplateEntity)entity);
					}
					break;
				case "TemplateToReportCategory":
					_alreadyFetchedTemplateToReportCategory = true;
					if(entity!=null)
					{
						this.TemplateToReportCategory.Add((TemplateToReportCategoryEntity)entity);
					}
					break;
				case "ReportCategoryCollectionViaReportCategoryToTemplate":
					_alreadyFetchedReportCategoryCollectionViaReportCategoryToTemplate = true;
					if(entity!=null)
					{
						this.ReportCategoryCollectionViaReportCategoryToTemplate.Add((ReportCategoryEntity)entity);
					}
					break;
				case "ReportCategoryCollectionViaTemplateToReportCategory":
					_alreadyFetchedReportCategoryCollectionViaTemplateToReportCategory = true;
					if(entity!=null)
					{
						this.ReportCategoryCollectionViaTemplateToReportCategory.Add((ReportCategoryEntity)entity);
					}
					break;
				case "ReportHeaderCollectionViaMessage":
					_alreadyFetchedReportHeaderCollectionViaMessage = true;
					if(entity!=null)
					{
						this.ReportHeaderCollectionViaMessage.Add((ReportHeaderEntity)entity);
					}
					break;
				case "UserCollectionViaMessage":
					_alreadyFetchedUserCollectionViaMessage = true;
					if(entity!=null)
					{
						this.UserCollectionViaMessage.Add((UserEntity)entity);
					}
					break;

				default:

					break;
			}
		}

		/// <summary> Sets the internal parameter related to the fieldname passed to the instance relatedEntity. </summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		/// <param name="fieldName">Name of field mapped onto the relation which resolves in the instance relatedEntity</param>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override void SetRelatedEntity(IEntity relatedEntity, string fieldName)
		{
			switch(fieldName)
			{
				case "Action":
					SetupSyncAction(relatedEntity);
					break;
				case "Message":
					_message.Add((MessageEntity)relatedEntity);
					break;
				case "ReportCategoryToTemplate":
					_reportCategoryToTemplate.Add((ReportCategoryToTemplateEntity)relatedEntity);
					break;
				case "TemplateToReportCategory":
					_templateToReportCategory.Add((TemplateToReportCategoryEntity)relatedEntity);
					break;

				default:

					break;
			}
		}
		
		/// <summary> Unsets the internal parameter related to the fieldname passed to the instance relatedEntity. Reverses the actions taken by SetRelatedEntity() </summary>
		/// <param name="relatedEntity">Instance to unset as the related entity of type entityType</param>
		/// <param name="fieldName">Name of field mapped onto the relation which resolves in the instance relatedEntity</param>
		/// <param name="signalRelatedEntityManyToOne">if set to true it will notify the manytoone side, if applicable.</param>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override void UnsetRelatedEntity(IEntity relatedEntity, string fieldName, bool signalRelatedEntityManyToOne)
		{
			switch(fieldName)
			{
				case "Action":
					DesetupSyncAction(false, true);
					break;
				case "Message":
					base.PerformRelatedEntityRemoval(_message, relatedEntity, signalRelatedEntityManyToOne);
					break;
				case "ReportCategoryToTemplate":
					base.PerformRelatedEntityRemoval(_reportCategoryToTemplate, relatedEntity, signalRelatedEntityManyToOne);
					break;
				case "TemplateToReportCategory":
					base.PerformRelatedEntityRemoval(_templateToReportCategory, relatedEntity, signalRelatedEntityManyToOne);
					break;

				default:

					break;
			}
		}

		/// <summary> Gets a collection of related entities referenced by this entity which depend on this entity (this entity is the PK side of their FK fields). These
		/// entities will have to be persisted after this entity during a recursive save.</summary>
		/// <returns>Collection with 0 or more IEntity objects, referenced by this entity</returns>
		public override List<IEntity> GetDependingRelatedEntities()
		{
			List<IEntity> toReturn = new List<IEntity>();


			return toReturn;
		}
		
		/// <summary> Gets a collection of related entities referenced by this entity which this entity depends on (this entity is the FK side of their PK fields). These
		/// entities will have to be persisted before this entity during a recursive save.</summary>
		/// <returns>Collection with 0 or more IEntity objects, referenced by this entity</returns>
		public override List<IEntity> GetDependentRelatedEntities()
		{
			List<IEntity> toReturn = new List<IEntity>();
			if(_action!=null)
			{
				toReturn.Add(_action);
			}


			return toReturn;
		}
		
		/// <summary> Gets a List of all entity collections stored as member variables in this entity. The contents of the ArrayList is
		/// used by the DataAccessAdapter to perform recursive saves. Only 1:n related collections are returned.</summary>
		/// <returns>Collection with 0 or more IEntityCollection objects, referenced by this entity</returns>
		public override List<IEntityCollection> GetMemberEntityCollections()
		{
			List<IEntityCollection> toReturn = new List<IEntityCollection>();
			toReturn.Add(_message);
			toReturn.Add(_reportCategoryToTemplate);
			toReturn.Add(_templateToReportCategory);

			return toReturn;
		}

		

		

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="templateId">PK value for Template which data should be fetched into this Template object</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 templateId)
		{
			return FetchUsingPK(templateId, null, null, null);
		}

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="templateId">PK value for Template which data should be fetched into this Template object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 templateId, IPrefetchPath prefetchPathToUse)
		{
			return FetchUsingPK(templateId, prefetchPathToUse, null, null);
		}

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="templateId">PK value for Template which data should be fetched into this Template object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <param name="contextToUse">The context to add the entity to if the fetch was succesful. </param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 templateId, IPrefetchPath prefetchPathToUse, Context contextToUse)
		{
			return Fetch(templateId, prefetchPathToUse, contextToUse, null);
		}

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="templateId">PK value for Template which data should be fetched into this Template object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <param name="contextToUse">The context to add the entity to if the fetch was succesful. </param>
		/// <param name="excludedIncludedFields">The list of IEntityField objects which have to be excluded or included for the fetch. 
		/// If null or empty, all fields are fetched (default). If an instance of ExcludeIncludeFieldsList is passed in and its ExcludeContainedFields property
		/// is set to false, the fields contained in excludedIncludedFields are kept in the query, the rest of the fields in the query are excluded.</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 templateId, IPrefetchPath prefetchPathToUse, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields)
		{
			return Fetch(templateId, prefetchPathToUse, contextToUse, excludedIncludedFields);
		}

		/// <summary> Refetches the Entity from the persistent storage. Refetch is used to re-load an Entity which is marked "Out-of-sync", due to a save action. 
		/// Refetching an empty Entity has no effect. </summary>
		/// <returns>true if Refetch succeeded, false otherwise</returns>
		public override bool Refetch()
		{
			return Fetch(this.TemplateId, null, null, null);
		}

		/// <summary> Returns true if the original value for the field with the fieldIndex passed in, read from the persistent storage was NULL, false otherwise.
		/// Should not be used for testing if the current value is NULL, use <see cref="TestCurrentFieldValueForNull"/> for that.</summary>
		/// <param name="fieldIndex">Index of the field to test if that field was NULL in the persistent storage</param>
		/// <returns>true if the field with the passed in index was NULL in the persistent storage, false otherwise</returns>
		public bool TestOriginalFieldValueForNull(TemplateFieldIndex fieldIndex)
		{
			return base.Fields[(int)fieldIndex].IsNull;
		}
		
		/// <summary>Returns true if the current value for the field with the fieldIndex passed in represents null/not defined, false otherwise.
		/// Should not be used for testing if the original value (read from the db) is NULL</summary>
		/// <param name="fieldIndex">Index of the field to test if its currentvalue is null/undefined</param>
		/// <returns>true if the field's value isn't defined yet, false otherwise</returns>
		public bool TestCurrentFieldValueForNull(TemplateFieldIndex fieldIndex)
		{
			return base.CheckIfCurrentFieldValueIsNull((int)fieldIndex);
		}

				
		/// <summary>Gets a list of all the EntityRelation objects the type of this instance has.</summary>
		/// <returns>A list of all the EntityRelation objects the type of this instance has. Hierarchy relations are excluded.</returns>
		public override List<IEntityRelation> GetAllRelations()
		{
			return new TemplateRelations().GetAllRelations();
		}


		/// <summary> Retrieves all related entities of type 'MessageEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <returns>Filled collection with all related entities of type 'MessageEntity'</returns>
		public CARMSData.CollectionClasses.MessageCollection GetMultiMessage(bool forceFetch)
		{
			return GetMultiMessage(forceFetch, _message.EntityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'MessageEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of type 'MessageEntity'</returns>
		public CARMSData.CollectionClasses.MessageCollection GetMultiMessage(bool forceFetch, IPredicateExpression filter)
		{
			return GetMultiMessage(forceFetch, _message.EntityFactoryToUse, filter);
		}

		/// <summary> Retrieves all related entities of type 'MessageEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public CARMSData.CollectionClasses.MessageCollection GetMultiMessage(bool forceFetch, IEntityFactory entityFactoryToUse)
		{
			return GetMultiMessage(forceFetch, entityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'MessageEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public virtual CARMSData.CollectionClasses.MessageCollection GetMultiMessage(bool forceFetch, IEntityFactory entityFactoryToUse, IPredicateExpression filter)
		{
 			if( ( !_alreadyFetchedMessage || forceFetch || _alwaysFetchMessage) && !base.IsSerializing && !base.IsDeserializing && !base.InDesignMode)
			{
				if(base.ParticipatesInTransaction)
				{
					if(!_message.ParticipatesInTransaction)
					{
						base.Transaction.Add(_message);
					}
				}
				_message.SuppressClearInGetMulti=!forceFetch;
				if(entityFactoryToUse!=null)
				{
					_message.EntityFactoryToUse = entityFactoryToUse;
				}
				_message.GetMultiManyToOne(null, this, null, filter);
				_message.SuppressClearInGetMulti=false;
				_alreadyFetchedMessage = true;
			}
			return _message;
		}

		/// <summary> Sets the collection parameters for the collection for 'Message'. These settings will be taken into account
		/// when the property Message is requested or GetMultiMessage is called.</summary>
		/// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return. When set to 0, this parameter is ignored</param>
		/// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified (null), no sorting is applied.</param>
		public virtual void SetCollectionParametersMessage(long maxNumberOfItemsToReturn, ISortExpression sortClauses)
		{
			_message.SortClauses=sortClauses;
			_message.MaxNumberOfItemsToReturn=maxNumberOfItemsToReturn;
		}

		/// <summary> Retrieves all related entities of type 'ReportCategoryToTemplateEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <returns>Filled collection with all related entities of type 'ReportCategoryToTemplateEntity'</returns>
		public CARMSData.CollectionClasses.ReportCategoryToTemplateCollection GetMultiReportCategoryToTemplate(bool forceFetch)
		{
			return GetMultiReportCategoryToTemplate(forceFetch, _reportCategoryToTemplate.EntityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'ReportCategoryToTemplateEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of type 'ReportCategoryToTemplateEntity'</returns>
		public CARMSData.CollectionClasses.ReportCategoryToTemplateCollection GetMultiReportCategoryToTemplate(bool forceFetch, IPredicateExpression filter)
		{
			return GetMultiReportCategoryToTemplate(forceFetch, _reportCategoryToTemplate.EntityFactoryToUse, filter);
		}

		/// <summary> Retrieves all related entities of type 'ReportCategoryToTemplateEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public CARMSData.CollectionClasses.ReportCategoryToTemplateCollection GetMultiReportCategoryToTemplate(bool forceFetch, IEntityFactory entityFactoryToUse)
		{
			return GetMultiReportCategoryToTemplate(forceFetch, entityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'ReportCategoryToTemplateEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public virtual CARMSData.CollectionClasses.ReportCategoryToTemplateCollection GetMultiReportCategoryToTemplate(bool forceFetch, IEntityFactory entityFactoryToUse, IPredicateExpression filter)
		{
 			if( ( !_alreadyFetchedReportCategoryToTemplate || forceFetch || _alwaysFetchReportCategoryToTemplate) && !base.IsSerializing && !base.IsDeserializing && !base.InDesignMode)
			{
				if(base.ParticipatesInTransaction)
				{
					if(!_reportCategoryToTemplate.ParticipatesInTransaction)
					{
						base.Transaction.Add(_reportCategoryToTemplate);
					}
				}
				_reportCategoryToTemplate.SuppressClearInGetMulti=!forceFetch;
				if(entityFactoryToUse!=null)
				{
					_reportCategoryToTemplate.EntityFactoryToUse = entityFactoryToUse;
				}
				_reportCategoryToTemplate.GetMultiManyToOne(null, this, filter);
				_reportCategoryToTemplate.SuppressClearInGetMulti=false;
				_alreadyFetchedReportCategoryToTemplate = true;
			}
			return _reportCategoryToTemplate;
		}

		/// <summary> Sets the collection parameters for the collection for 'ReportCategoryToTemplate'. These settings will be taken into account
		/// when the property ReportCategoryToTemplate is requested or GetMultiReportCategoryToTemplate is called.</summary>
		/// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return. When set to 0, this parameter is ignored</param>
		/// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified (null), no sorting is applied.</param>
		public virtual void SetCollectionParametersReportCategoryToTemplate(long maxNumberOfItemsToReturn, ISortExpression sortClauses)
		{
			_reportCategoryToTemplate.SortClauses=sortClauses;
			_reportCategoryToTemplate.MaxNumberOfItemsToReturn=maxNumberOfItemsToReturn;
		}

		/// <summary> Retrieves all related entities of type 'TemplateToReportCategoryEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <returns>Filled collection with all related entities of type 'TemplateToReportCategoryEntity'</returns>
		public CARMSData.CollectionClasses.TemplateToReportCategoryCollection GetMultiTemplateToReportCategory(bool forceFetch)
		{
			return GetMultiTemplateToReportCategory(forceFetch, _templateToReportCategory.EntityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'TemplateToReportCategoryEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of type 'TemplateToReportCategoryEntity'</returns>
		public CARMSData.CollectionClasses.TemplateToReportCategoryCollection GetMultiTemplateToReportCategory(bool forceFetch, IPredicateExpression filter)
		{
			return GetMultiTemplateToReportCategory(forceFetch, _templateToReportCategory.EntityFactoryToUse, filter);
		}

		/// <summary> Retrieves all related entities of type 'TemplateToReportCategoryEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public CARMSData.CollectionClasses.TemplateToReportCategoryCollection GetMultiTemplateToReportCategory(bool forceFetch, IEntityFactory entityFactoryToUse)
		{
			return GetMultiTemplateToReportCategory(forceFetch, entityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'TemplateToReportCategoryEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public virtual CARMSData.CollectionClasses.TemplateToReportCategoryCollection GetMultiTemplateToReportCategory(bool forceFetch, IEntityFactory entityFactoryToUse, IPredicateExpression filter)
		{
 			if( ( !_alreadyFetchedTemplateToReportCategory || forceFetch || _alwaysFetchTemplateToReportCategory) && !base.IsSerializing && !base.IsDeserializing && !base.InDesignMode)
			{
				if(base.ParticipatesInTransaction)
				{
					if(!_templateToReportCategory.ParticipatesInTransaction)
					{
						base.Transaction.Add(_templateToReportCategory);
					}
				}
				_templateToReportCategory.SuppressClearInGetMulti=!forceFetch;
				if(entityFactoryToUse!=null)
				{
					_templateToReportCategory.EntityFactoryToUse = entityFactoryToUse;
				}
				_templateToReportCategory.GetMultiManyToOne(null, this, filter);
				_templateToReportCategory.SuppressClearInGetMulti=false;
				_alreadyFetchedTemplateToReportCategory = true;
			}
			return _templateToReportCategory;
		}

		/// <summary> Sets the collection parameters for the collection for 'TemplateToReportCategory'. These settings will be taken into account
		/// when the property TemplateToReportCategory is requested or GetMultiTemplateToReportCategory is called.</summary>
		/// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return. When set to 0, this parameter is ignored</param>
		/// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified (null), no sorting is applied.</param>
		public virtual void SetCollectionParametersTemplateToReportCategory(long maxNumberOfItemsToReturn, ISortExpression sortClauses)
		{
			_templateToReportCategory.SortClauses=sortClauses;
			_templateToReportCategory.MaxNumberOfItemsToReturn=maxNumberOfItemsToReturn;
		}

		/// <summary> Retrieves all related entities of type 'ReportCategoryEntity' using a relation of type 'm:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <returns>Filled collection with all related entities of type 'ReportCategoryEntity'</returns>
		public CARMSData.CollectionClasses.ReportCategoryCollection GetMultiReportCategoryCollectionViaReportCategoryToTemplate(bool forceFetch)
		{
			return GetMultiReportCategoryCollectionViaReportCategoryToTemplate(forceFetch, _reportCategoryCollectionViaReportCategoryToTemplate.EntityFactoryToUse);
		}

		/// <summary> Retrieves all related entities of type 'ReportCategoryEntity' using a relation of type 'm:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToMany() routine.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public CARMSData.CollectionClasses.ReportCategoryCollection GetMultiReportCategoryCollectionViaReportCategoryToTemplate(bool forceFetch, IEntityFactory entityFactoryToUse)
		{
 			if( ( !_alreadyFetchedReportCategoryCollectionViaReportCategoryToTemplate || forceFetch || _alwaysFetchReportCategoryCollectionViaReportCategoryToTemplate) && !base.IsSerializing && !base.IsDeserializing && !base.InDesignMode)
			{
				if(base.ParticipatesInTransaction)
				{
					if(!_reportCategoryCollectionViaReportCategoryToTemplate.ParticipatesInTransaction)
					{
						base.Transaction.Add(_reportCategoryCollectionViaReportCategoryToTemplate);
					}
				}
				IPredicateExpression filter = new PredicateExpression();
				filter.Add(new FieldCompareValuePredicate(TemplateFields.TemplateId, ComparisonOperator.Equal, this.TemplateId, "TemplateEntity__"));
				_reportCategoryCollectionViaReportCategoryToTemplate.SuppressClearInGetMulti=!forceFetch;
				if(entityFactoryToUse!=null)
				{
					_reportCategoryCollectionViaReportCategoryToTemplate.EntityFactoryToUse = entityFactoryToUse;
				}
				_reportCategoryCollectionViaReportCategoryToTemplate.GetMulti(filter, GetRelationsForField("ReportCategoryCollectionViaReportCategoryToTemplate"));
				_reportCategoryCollectionViaReportCategoryToTemplate.SuppressClearInGetMulti=false;
				_alreadyFetchedReportCategoryCollectionViaReportCategoryToTemplate = true;
			}
			return _reportCategoryCollectionViaReportCategoryToTemplate;
		}

		/// <summary> Sets the collection parameters for the collection for 'ReportCategoryCollectionViaReportCategoryToTemplate'. These settings will be taken into account
		/// when the property ReportCategoryCollectionViaReportCategoryToTemplate is requested or GetMultiReportCategoryCollectionViaReportCategoryToTemplate is called.</summary>
		/// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return. When set to 0, this parameter is ignored</param>
		/// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified (null), no sorting is applied.</param>
		public virtual void SetCollectionParametersReportCategoryCollectionViaReportCategoryToTemplate(long maxNumberOfItemsToReturn, ISortExpression sortClauses)
		{
			_reportCategoryCollectionViaReportCategoryToTemplate.SortClauses=sortClauses;
			_reportCategoryCollectionViaReportCategoryToTemplate.MaxNumberOfItemsToReturn=maxNumberOfItemsToReturn;
		}

		/// <summary> Retrieves all related entities of type 'ReportCategoryEntity' using a relation of type 'm:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <returns>Filled collection with all related entities of type 'ReportCategoryEntity'</returns>
		public CARMSData.CollectionClasses.ReportCategoryCollection GetMultiReportCategoryCollectionViaTemplateToReportCategory(bool forceFetch)
		{
			return GetMultiReportCategoryCollectionViaTemplateToReportCategory(forceFetch, _reportCategoryCollectionViaTemplateToReportCategory.EntityFactoryToUse);
		}

		/// <summary> Retrieves all related entities of type 'ReportCategoryEntity' using a relation of type 'm:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToMany() routine.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public CARMSData.CollectionClasses.ReportCategoryCollection GetMultiReportCategoryCollectionViaTemplateToReportCategory(bool forceFetch, IEntityFactory entityFactoryToUse)
		{
 			if( ( !_alreadyFetchedReportCategoryCollectionViaTemplateToReportCategory || forceFetch || _alwaysFetchReportCategoryCollectionViaTemplateToReportCategory) && !base.IsSerializing && !base.IsDeserializing && !base.InDesignMode)
			{
				if(base.ParticipatesInTransaction)
				{
					if(!_reportCategoryCollectionViaTemplateToReportCategory.ParticipatesInTransaction)
					{
						base.Transaction.Add(_reportCategoryCollectionViaTemplateToReportCategory);
					}
				}
				IPredicateExpression filter = new PredicateExpression();
				filter.Add(new FieldCompareValuePredicate(TemplateFields.TemplateId, ComparisonOperator.Equal, this.TemplateId, "TemplateEntity__"));
				_reportCategoryCollectionViaTemplateToReportCategory.SuppressClearInGetMulti=!forceFetch;
				if(entityFactoryToUse!=null)
				{
					_reportCategoryCollectionViaTemplateToReportCategory.EntityFactoryToUse = entityFactoryToUse;
				}
				_reportCategoryCollectionViaTemplateToReportCategory.GetMulti(filter, GetRelationsForField("ReportCategoryCollectionViaTemplateToReportCategory"));
				_reportCategoryCollectionViaTemplateToReportCategory.SuppressClearInGetMulti=false;
				_alreadyFetchedReportCategoryCollectionViaTemplateToReportCategory = true;
			}
			return _reportCategoryCollectionViaTemplateToReportCategory;
		}

		/// <summary> Sets the collection parameters for the collection for 'ReportCategoryCollectionViaTemplateToReportCategory'. These settings will be taken into account
		/// when the property ReportCategoryCollectionViaTemplateToReportCategory is requested or GetMultiReportCategoryCollectionViaTemplateToReportCategory is called.</summary>
		/// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return. When set to 0, this parameter is ignored</param>
		/// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified (null), no sorting is applied.</param>
		public virtual void SetCollectionParametersReportCategoryCollectionViaTemplateToReportCategory(long maxNumberOfItemsToReturn, ISortExpression sortClauses)
		{
			_reportCategoryCollectionViaTemplateToReportCategory.SortClauses=sortClauses;
			_reportCategoryCollectionViaTemplateToReportCategory.MaxNumberOfItemsToReturn=maxNumberOfItemsToReturn;
		}

		/// <summary> Retrieves all related entities of type 'ReportHeaderEntity' using a relation of type 'm:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <returns>Filled collection with all related entities of type 'ReportHeaderEntity'</returns>
		public CARMSData.CollectionClasses.ReportHeaderCollection GetMultiReportHeaderCollectionViaMessage(bool forceFetch)
		{
			return GetMultiReportHeaderCollectionViaMessage(forceFetch, _reportHeaderCollectionViaMessage.EntityFactoryToUse);
		}

		/// <summary> Retrieves all related entities of type 'ReportHeaderEntity' using a relation of type 'm:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToMany() routine.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public CARMSData.CollectionClasses.ReportHeaderCollection GetMultiReportHeaderCollectionViaMessage(bool forceFetch, IEntityFactory entityFactoryToUse)
		{
 			if( ( !_alreadyFetchedReportHeaderCollectionViaMessage || forceFetch || _alwaysFetchReportHeaderCollectionViaMessage) && !base.IsSerializing && !base.IsDeserializing && !base.InDesignMode)
			{
				if(base.ParticipatesInTransaction)
				{
					if(!_reportHeaderCollectionViaMessage.ParticipatesInTransaction)
					{
						base.Transaction.Add(_reportHeaderCollectionViaMessage);
					}
				}
				IPredicateExpression filter = new PredicateExpression();
				filter.Add(new FieldCompareValuePredicate(TemplateFields.TemplateId, ComparisonOperator.Equal, this.TemplateId, "TemplateEntity__"));
				_reportHeaderCollectionViaMessage.SuppressClearInGetMulti=!forceFetch;
				if(entityFactoryToUse!=null)
				{
					_reportHeaderCollectionViaMessage.EntityFactoryToUse = entityFactoryToUse;
				}
				_reportHeaderCollectionViaMessage.GetMulti(filter, GetRelationsForField("ReportHeaderCollectionViaMessage"));
				_reportHeaderCollectionViaMessage.SuppressClearInGetMulti=false;
				_alreadyFetchedReportHeaderCollectionViaMessage = true;
			}
			return _reportHeaderCollectionViaMessage;
		}

		/// <summary> Sets the collection parameters for the collection for 'ReportHeaderCollectionViaMessage'. These settings will be taken into account
		/// when the property ReportHeaderCollectionViaMessage is requested or GetMultiReportHeaderCollectionViaMessage is called.</summary>
		/// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return. When set to 0, this parameter is ignored</param>
		/// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified (null), no sorting is applied.</param>
		public virtual void SetCollectionParametersReportHeaderCollectionViaMessage(long maxNumberOfItemsToReturn, ISortExpression sortClauses)
		{
			_reportHeaderCollectionViaMessage.SortClauses=sortClauses;
			_reportHeaderCollectionViaMessage.MaxNumberOfItemsToReturn=maxNumberOfItemsToReturn;
		}

		/// <summary> Retrieves all related entities of type 'UserEntity' using a relation of type 'm:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <returns>Filled collection with all related entities of type 'UserEntity'</returns>
		public CARMSData.CollectionClasses.UserCollection GetMultiUserCollectionViaMessage(bool forceFetch)
		{
			return GetMultiUserCollectionViaMessage(forceFetch, _userCollectionViaMessage.EntityFactoryToUse);
		}

		/// <summary> Retrieves all related entities of type 'UserEntity' using a relation of type 'm:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToMany() routine.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public CARMSData.CollectionClasses.UserCollection GetMultiUserCollectionViaMessage(bool forceFetch, IEntityFactory entityFactoryToUse)
		{
 			if( ( !_alreadyFetchedUserCollectionViaMessage || forceFetch || _alwaysFetchUserCollectionViaMessage) && !base.IsSerializing && !base.IsDeserializing && !base.InDesignMode)
			{
				if(base.ParticipatesInTransaction)
				{
					if(!_userCollectionViaMessage.ParticipatesInTransaction)
					{
						base.Transaction.Add(_userCollectionViaMessage);
					}
				}
				IPredicateExpression filter = new PredicateExpression();
				filter.Add(new FieldCompareValuePredicate(TemplateFields.TemplateId, ComparisonOperator.Equal, this.TemplateId, "TemplateEntity__"));
				_userCollectionViaMessage.SuppressClearInGetMulti=!forceFetch;
				if(entityFactoryToUse!=null)
				{
					_userCollectionViaMessage.EntityFactoryToUse = entityFactoryToUse;
				}
				_userCollectionViaMessage.GetMulti(filter, GetRelationsForField("UserCollectionViaMessage"));
				_userCollectionViaMessage.SuppressClearInGetMulti=false;
				_alreadyFetchedUserCollectionViaMessage = true;
			}
			return _userCollectionViaMessage;
		}

		/// <summary> Sets the collection parameters for the collection for 'UserCollectionViaMessage'. These settings will be taken into account
		/// when the property UserCollectionViaMessage is requested or GetMultiUserCollectionViaMessage is called.</summary>
		/// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return. When set to 0, this parameter is ignored</param>
		/// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified (null), no sorting is applied.</param>
		public virtual void SetCollectionParametersUserCollectionViaMessage(long maxNumberOfItemsToReturn, ISortExpression sortClauses)
		{
			_userCollectionViaMessage.SortClauses=sortClauses;
			_userCollectionViaMessage.MaxNumberOfItemsToReturn=maxNumberOfItemsToReturn;
		}

		/// <summary> Retrieves the related entity of type 'ActionEntity', using a relation of type 'n:1'</summary>
		/// <returns>A fetched entity of type 'ActionEntity' which is related to this entity.</returns>
		public ActionEntity GetSingleAction()
		{
			return GetSingleAction(false);
		}

		/// <summary> Retrieves the related entity of type 'ActionEntity', using a relation of type 'n:1'</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
		/// <returns>A fetched entity of type 'ActionEntity' which is related to this entity.</returns>
		public virtual ActionEntity GetSingleAction(bool forceFetch)
		{
			if( ( !_alreadyFetchedAction || forceFetch || _alwaysFetchAction) && !base.IsSerializing && !base.IsDeserializing  && !base.InDesignMode)			
			{
				bool performLazyLoading = base.CheckIfLazyLoadingShouldOccur(TemplateEntity.Relations.ActionEntityUsingShowActionId);

				ActionEntity newEntity = new ActionEntity();
				if(base.ParticipatesInTransaction)
				{
					base.Transaction.Add(newEntity);
				}
				bool fetchResult = false;
				if(performLazyLoading)
				{
					fetchResult = newEntity.FetchUsingPK(this.ShowActionId);
				}
				if(fetchResult)
				{
					if(base.ActiveContext!=null)
					{
						newEntity = (ActionEntity)base.ActiveContext.Get(newEntity);
					}
					this.Action = newEntity;
				}
				else
				{
					if(_actionReturnsNewIfNotFound)
					{
						if(performLazyLoading || (!performLazyLoading && (_action == null)))
						{
							this.Action = newEntity;
						}
					}
					else
					{
						this.Action = null;
					}
				}
				_alreadyFetchedAction = fetchResult;
				if(base.ParticipatesInTransaction && !fetchResult)
				{
					base.Transaction.Remove(newEntity);
				}
			}
			return _action;
		}


		/// <summary> Performs the insert action of a new Entity to the persistent storage.</summary>
		/// <returns>true if succeeded, false otherwise</returns>
		protected override bool InsertEntity()
		{
			TemplateDAO dao = (TemplateDAO)CreateDAOInstance();
			return dao.AddNew(base.Fields, base.Transaction);
		}
		
		/// <summary> Adds the internals to the active context. </summary>
		protected override void AddInternalsToContext()
		{
			_message.ActiveContext = base.ActiveContext;
			_reportCategoryToTemplate.ActiveContext = base.ActiveContext;
			_templateToReportCategory.ActiveContext = base.ActiveContext;
			_reportCategoryCollectionViaReportCategoryToTemplate.ActiveContext = base.ActiveContext;
			_reportCategoryCollectionViaTemplateToReportCategory.ActiveContext = base.ActiveContext;
			_reportHeaderCollectionViaMessage.ActiveContext = base.ActiveContext;
			_userCollectionViaMessage.ActiveContext = base.ActiveContext;
			if(_action!=null)
			{
				_action.ActiveContext = base.ActiveContext;
			}


		}


		/// <summary> Performs the update action of an existing Entity to the persistent storage.</summary>
		/// <returns>true if succeeded, false otherwise</returns>
		protected override bool UpdateEntity()
		{
			TemplateDAO dao = (TemplateDAO)CreateDAOInstance();
			return dao.UpdateExisting(base.Fields, base.Transaction);
		}
		
		/// <summary> Performs the update action of an existing Entity to the persistent storage.</summary>
		/// <param name="updateRestriction">Predicate expression, meant for concurrency checks in an Update query</param>
		/// <returns>true if succeeded, false otherwise</returns>
		protected override bool UpdateEntity(IPredicate updateRestriction)
		{
			TemplateDAO dao = (TemplateDAO)CreateDAOInstance();
			return dao.UpdateExisting(base.Fields, base.Transaction, updateRestriction);
		}
	
		/// <summary> Initializes the class with empty data, as if it is a new Entity.</summary>
		/// <param name="validatorToUse">Validator to use.</param>
		protected virtual void InitClassEmpty(IValidator validatorToUse)
		{
			OnInitializing();
			base.Fields = CreateFields();
			base.IsNew=true;
			base.Validator = validatorToUse;

			InitClassMembers();
			
			// __LLBLGENPRO_USER_CODE_REGION_START InitClassEmpty
			// __LLBLGENPRO_USER_CODE_REGION_END

			OnInitialized();
		}
		
		/// <summary>Creates entity fields object for this entity. Used in constructor to setup this entity in a polymorphic scenario.</summary>
		protected virtual IEntityFields CreateFields()
		{
			return EntityFieldsFactory.CreateEntityFieldsObject(CARMSData.EntityType.TemplateEntity);
		}
		
		/// <summary>Creates a new transaction object</summary>
		/// <param name="levelOfIsolation">The level of isolation.</param>
		/// <param name="name">The name.</param>
		protected override ITransaction CreateTransaction( IsolationLevel levelOfIsolation, string name )
		{
			return new Transaction(levelOfIsolation, name);
		}

		/// <summary>
		/// Creates the ITypeDefaultValue instance used to provide default values for value types which aren't of type nullable(of T)
		/// </summary>
		/// <returns></returns>
		protected override ITypeDefaultValue CreateTypeDefaultValueProvider()
		{
			return new TypeDefaultValue();
		}

		/// <summary>
		/// Gets all related data objects, stored by name. The name is the field name mapped onto the relation for that particular data element. 
		/// </summary>
		/// <returns>Dictionary with per name the related referenced data element, which can be an entity collection or an entity or null</returns>
		public override Dictionary<string, object> GetRelatedData()
		{
			Dictionary<string, object> toReturn = new Dictionary<string, object>();
			toReturn.Add("Action", _action);
			toReturn.Add("Message", _message);
			toReturn.Add("ReportCategoryToTemplate", _reportCategoryToTemplate);
			toReturn.Add("TemplateToReportCategory", _templateToReportCategory);
			toReturn.Add("ReportCategoryCollectionViaReportCategoryToTemplate", _reportCategoryCollectionViaReportCategoryToTemplate);
			toReturn.Add("ReportCategoryCollectionViaTemplateToReportCategory", _reportCategoryCollectionViaTemplateToReportCategory);
			toReturn.Add("ReportHeaderCollectionViaMessage", _reportHeaderCollectionViaMessage);
			toReturn.Add("UserCollectionViaMessage", _userCollectionViaMessage);

			return toReturn;
		}
		

		/// <summary> Initializes the the entity and fetches the data related to the entity in this entity.</summary>
		/// <param name="templateId">PK value for Template which data should be fetched into this Template object</param>
		/// <param name="validator">The validator object for this TemplateEntity</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		protected virtual void InitClassFetch(System.Int32 templateId, IValidator validator, IPrefetchPath prefetchPathToUse)
		{
			OnInitializing();
			base.Validator = validator;
			InitClassMembers();
			base.Fields = CreateFields();
			bool wasSuccesful = Fetch(templateId, prefetchPathToUse, null, null);
			base.IsNew = !wasSuccesful;

			
			// __LLBLGENPRO_USER_CODE_REGION_START InitClassFetch
			// __LLBLGENPRO_USER_CODE_REGION_END

			OnInitialized();
		}

		/// <summary> Initializes the class members</summary>
		private void InitClassMembers()
		{
			_message = new CARMSData.CollectionClasses.MessageCollection(new MessageEntityFactory());
			_message.SetContainingEntityInfo(this, "Template");
			_alwaysFetchMessage = false;
			_alreadyFetchedMessage = false;
			_reportCategoryToTemplate = new CARMSData.CollectionClasses.ReportCategoryToTemplateCollection(new ReportCategoryToTemplateEntityFactory());
			_reportCategoryToTemplate.SetContainingEntityInfo(this, "Template");
			_alwaysFetchReportCategoryToTemplate = false;
			_alreadyFetchedReportCategoryToTemplate = false;
			_templateToReportCategory = new CARMSData.CollectionClasses.TemplateToReportCategoryCollection(new TemplateToReportCategoryEntityFactory());
			_templateToReportCategory.SetContainingEntityInfo(this, "Template");
			_alwaysFetchTemplateToReportCategory = false;
			_alreadyFetchedTemplateToReportCategory = false;
			_reportCategoryCollectionViaReportCategoryToTemplate = new CARMSData.CollectionClasses.ReportCategoryCollection(new ReportCategoryEntityFactory());
			_alwaysFetchReportCategoryCollectionViaReportCategoryToTemplate = false;
			_alreadyFetchedReportCategoryCollectionViaReportCategoryToTemplate = false;
			_reportCategoryCollectionViaTemplateToReportCategory = new CARMSData.CollectionClasses.ReportCategoryCollection(new ReportCategoryEntityFactory());
			_alwaysFetchReportCategoryCollectionViaTemplateToReportCategory = false;
			_alreadyFetchedReportCategoryCollectionViaTemplateToReportCategory = false;
			_reportHeaderCollectionViaMessage = new CARMSData.CollectionClasses.ReportHeaderCollection(new ReportHeaderEntityFactory());
			_alwaysFetchReportHeaderCollectionViaMessage = false;
			_alreadyFetchedReportHeaderCollectionViaMessage = false;
			_userCollectionViaMessage = new CARMSData.CollectionClasses.UserCollection(new UserEntityFactory());
			_alwaysFetchUserCollectionViaMessage = false;
			_alreadyFetchedUserCollectionViaMessage = false;
			_action = null;
			_actionReturnsNewIfNotFound = true;
			_alwaysFetchAction = false;
			_alreadyFetchedAction = false;


			PerformDependencyInjection();
			
			// __LLBLGENPRO_USER_CODE_REGION_START InitClassMembers
			// __LLBLGENPRO_USER_CODE_REGION_END
			OnInitClassMembersComplete();
		}

		#region Custom Property Hashtable Setup
		/// <summary> Initializes the hashtables for the entity type and entity field custom properties. </summary>
		private static void SetupCustomPropertyHashtables()
		{
			_customProperties = new Dictionary<string, string>();
			_fieldsCustomProperties = new Dictionary<string, Dictionary<string, string>>();

			Dictionary<string, string> fieldHashtable = null;
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("TemplateId", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("FromActionId", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("ShowActionId", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("EventUserId", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("EventDepartmentId", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("TemplateName", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("TemplateSubject", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("TemplateContent", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("Remark", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("CreateDate", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("TargetUrl", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("Added", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("Changes", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("Remove", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("Printing", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("Export", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("ToConfirm", fieldHashtable);
		}
		#endregion


		/// <summary> Removes the sync logic for member _action</summary>
		/// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
		/// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
		private void DesetupSyncAction(bool signalRelatedEntity, bool resetFKFields)
		{
			base.PerformDesetupSyncRelatedEntity( _action, new PropertyChangedEventHandler( OnActionPropertyChanged ), "Action", TemplateEntity.Relations.ActionEntityUsingShowActionId, true, signalRelatedEntity, "Template", resetFKFields, new int[] { (int)TemplateFieldIndex.ShowActionId } );		
			_action = null;
		}
		
		/// <summary> setups the sync logic for member _action</summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		private void SetupSyncAction(IEntity relatedEntity)
		{
			if(_action!=relatedEntity)
			{		
				DesetupSyncAction(true, true);
				_action = (ActionEntity)relatedEntity;
				base.PerformSetupSyncRelatedEntity( _action, new PropertyChangedEventHandler( OnActionPropertyChanged ), "Action", TemplateEntity.Relations.ActionEntityUsingShowActionId, true, ref _alreadyFetchedAction, new string[] {  } );
			}
		}

		/// <summary>Handles property change events of properties in a related entity.</summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnActionPropertyChanged( object sender, PropertyChangedEventArgs e )
		{
			switch( e.PropertyName )
			{
				default:
					break;
			}
		}


		/// <summary> Fetches the entity from the persistent storage. Fetch simply reads the entity into an EntityFields object. </summary>
		/// <param name="templateId">PK value for Template which data should be fetched into this Template object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <param name="contextToUse">The context to add the entity to if the fetch was succesful. </param>
		/// <param name="excludedIncludedFields">The list of IEntityField objects which have to be excluded or included for the fetch. 
		/// If null or empty, all fields are fetched (default). If an instance of ExcludeIncludeFieldsList is passed in and its ExcludeContainedFields property
		/// is set to false, the fields contained in excludedIncludedFields are kept in the query, the rest of the fields in the query are excluded.</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		private bool Fetch(System.Int32 templateId, IPrefetchPath prefetchPathToUse, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields)
		{
			try
			{
				OnFetch();
				IDao dao = this.CreateDAOInstance();
				base.Fields[(int)TemplateFieldIndex.TemplateId].ForcedCurrentValueWrite(templateId);
				dao.FetchExisting(this, base.Transaction, prefetchPathToUse, contextToUse, excludedIncludedFields);
				return (base.Fields.State == EntityState.Fetched);
			}
			finally
			{
				OnFetchComplete();
			}
		}


		/// <summary> Creates the DAO instance for this type</summary>
		/// <returns></returns>
		protected override IDao CreateDAOInstance()
		{
			return DAOFactory.CreateTemplateDAO();
		}
		
		/// <summary> Creates the entity factory for this type.</summary>
		/// <returns></returns>
		protected override IEntityFactory CreateEntityFactory()
		{
			return new TemplateEntityFactory();
		}

		#region Class Property Declarations
		/// <summary> The relations object holding all relations of this entity with other entity classes.</summary>
		public  static TemplateRelations Relations
		{
			get	{ return new TemplateRelations(); }
		}
		
		/// <summary> The custom properties for this entity type.</summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		public  static Dictionary<string, string> CustomProperties
		{
			get { return _customProperties;}
		}


		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'Message' 
		/// for this entity. Add the object returned by this property to an existing PrefetchPath instance.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathMessage
		{
			get
			{
				return new PrefetchPathElement(new CARMSData.CollectionClasses.MessageCollection(),
					(IEntityRelation)GetRelationsForField("Message")[0], (int)CARMSData.EntityType.TemplateEntity, (int)CARMSData.EntityType.MessageEntity, 0, null, null, null, "Message", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToMany);
			}
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'ReportCategoryToTemplate' 
		/// for this entity. Add the object returned by this property to an existing PrefetchPath instance.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathReportCategoryToTemplate
		{
			get
			{
				return new PrefetchPathElement(new CARMSData.CollectionClasses.ReportCategoryToTemplateCollection(),
					(IEntityRelation)GetRelationsForField("ReportCategoryToTemplate")[0], (int)CARMSData.EntityType.TemplateEntity, (int)CARMSData.EntityType.ReportCategoryToTemplateEntity, 0, null, null, null, "ReportCategoryToTemplate", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToMany);
			}
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'TemplateToReportCategory' 
		/// for this entity. Add the object returned by this property to an existing PrefetchPath instance.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathTemplateToReportCategory
		{
			get
			{
				return new PrefetchPathElement(new CARMSData.CollectionClasses.TemplateToReportCategoryCollection(),
					(IEntityRelation)GetRelationsForField("TemplateToReportCategory")[0], (int)CARMSData.EntityType.TemplateEntity, (int)CARMSData.EntityType.TemplateToReportCategoryEntity, 0, null, null, null, "TemplateToReportCategory", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToMany);
			}
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'ReportCategory' 
		/// for this entity. Add the object returned by this property to an existing PrefetchPath instance.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathReportCategoryCollectionViaReportCategoryToTemplate
		{
			get
			{
				IEntityRelation intermediateRelation = TemplateEntity.Relations.ReportCategoryToTemplateEntityUsingTemplateId;
				intermediateRelation.SetAliases(string.Empty, "ReportCategoryToTemplate_");
				return new PrefetchPathElement(new CARMSData.CollectionClasses.ReportCategoryCollection(), intermediateRelation,
					(int)CARMSData.EntityType.TemplateEntity, (int)CARMSData.EntityType.ReportCategoryEntity, 0, null, null, GetRelationsForField("ReportCategoryCollectionViaReportCategoryToTemplate"), "ReportCategoryCollectionViaReportCategoryToTemplate", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.ManyToMany);
			}
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'ReportCategory' 
		/// for this entity. Add the object returned by this property to an existing PrefetchPath instance.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathReportCategoryCollectionViaTemplateToReportCategory
		{
			get
			{
				IEntityRelation intermediateRelation = TemplateEntity.Relations.TemplateToReportCategoryEntityUsingTemplateId;
				intermediateRelation.SetAliases(string.Empty, "TemplateToReportCategory_");
				return new PrefetchPathElement(new CARMSData.CollectionClasses.ReportCategoryCollection(), intermediateRelation,
					(int)CARMSData.EntityType.TemplateEntity, (int)CARMSData.EntityType.ReportCategoryEntity, 0, null, null, GetRelationsForField("ReportCategoryCollectionViaTemplateToReportCategory"), "ReportCategoryCollectionViaTemplateToReportCategory", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.ManyToMany);
			}
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'ReportHeader' 
		/// for this entity. Add the object returned by this property to an existing PrefetchPath instance.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathReportHeaderCollectionViaMessage
		{
			get
			{
				IEntityRelation intermediateRelation = TemplateEntity.Relations.MessageEntityUsingTemplateId;
				intermediateRelation.SetAliases(string.Empty, "Message_");
				return new PrefetchPathElement(new CARMSData.CollectionClasses.ReportHeaderCollection(), intermediateRelation,
					(int)CARMSData.EntityType.TemplateEntity, (int)CARMSData.EntityType.ReportHeaderEntity, 0, null, null, GetRelationsForField("ReportHeaderCollectionViaMessage"), "ReportHeaderCollectionViaMessage", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.ManyToMany);
			}
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'User' 
		/// for this entity. Add the object returned by this property to an existing PrefetchPath instance.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathUserCollectionViaMessage
		{
			get
			{
				IEntityRelation intermediateRelation = TemplateEntity.Relations.MessageEntityUsingTemplateId;
				intermediateRelation.SetAliases(string.Empty, "Message_");
				return new PrefetchPathElement(new CARMSData.CollectionClasses.UserCollection(), intermediateRelation,
					(int)CARMSData.EntityType.TemplateEntity, (int)CARMSData.EntityType.UserEntity, 0, null, null, GetRelationsForField("UserCollectionViaMessage"), "UserCollectionViaMessage", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.ManyToMany);
			}
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'Action' 
		/// for this entity. Add the object returned by this property to an existing PrefetchPath instance.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathAction
		{
			get
			{
				return new PrefetchPathElement(new CARMSData.CollectionClasses.ActionCollection(),
					(IEntityRelation)GetRelationsForField("Action")[0], (int)CARMSData.EntityType.TemplateEntity, (int)CARMSData.EntityType.ActionEntity, 0, null, null, null, "Action", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.ManyToOne);
			}
		}


		/// <summary>Returns the full name for this entity, which is important for the DAO to find back persistence info for this entity.</summary>
		[Browsable(false), XmlIgnore]
		public override string LLBLGenProEntityName
		{
			get { return "TemplateEntity";}
		}

		/// <summary> The custom properties for the type of this entity instance.</summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		[Browsable(false), XmlIgnore]
		public override Dictionary<string, string> CustomPropertiesOfType
		{
			get { return TemplateEntity.CustomProperties;}
		}

		/// <summary> The custom properties for the fields of this entity type. The returned Hashtable contains per fieldname a hashtable of name-value pairs. </summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		public  static Dictionary<string, Dictionary<string, string>> FieldsCustomProperties
		{
			get { return _fieldsCustomProperties;}
		}

		/// <summary> The custom properties for the fields of the type of this entity instance. The returned Hashtable contains per fieldname a hashtable of name-value pairs. </summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		[Browsable(false), XmlIgnore]
		public override Dictionary<string, Dictionary<string, string>> FieldsCustomPropertiesOfType
		{
			get { return TemplateEntity.FieldsCustomProperties;}
		}

		/// <summary> The TemplateId property of the Entity Template<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Template"."TemplateID"<br/>
		/// Table field type characteristics (type, precision, scale, length): Int, 10, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, true, true</remarks>
		public virtual System.Int32 TemplateId
		{
			get { return (System.Int32)GetValue((int)TemplateFieldIndex.TemplateId, true); }
			set	{ SetValue((int)TemplateFieldIndex.TemplateId, value, true); }
		}
		/// <summary> The FromActionId property of the Entity Template<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Template"."FromActionID"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 50<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual System.String FromActionId
		{
			get { return (System.String)GetValue((int)TemplateFieldIndex.FromActionId, true); }
			set	{ SetValue((int)TemplateFieldIndex.FromActionId, value, true); }
		}
		/// <summary> The ShowActionId property of the Entity Template<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Template"."ShowActionID"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 50<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual System.String ShowActionId
		{
			get { return (System.String)GetValue((int)TemplateFieldIndex.ShowActionId, true); }
			set	{ SetValue((int)TemplateFieldIndex.ShowActionId, value, true); }
		}
		/// <summary> The EventUserId property of the Entity Template<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Template"."EventUserID"<br/>
		/// Table field type characteristics (type, precision, scale, length): Int, 10, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual Nullable<System.Int32> EventUserId
		{
			get { return (Nullable<System.Int32>)GetValue((int)TemplateFieldIndex.EventUserId, false); }
			set	{ SetValue((int)TemplateFieldIndex.EventUserId, value, true); }
		}
		/// <summary> The EventDepartmentId property of the Entity Template<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Template"."EventDepartmentID"<br/>
		/// Table field type characteristics (type, precision, scale, length): Int, 10, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual Nullable<System.Int32> EventDepartmentId
		{
			get { return (Nullable<System.Int32>)GetValue((int)TemplateFieldIndex.EventDepartmentId, false); }
			set	{ SetValue((int)TemplateFieldIndex.EventDepartmentId, value, true); }
		}
		/// <summary> The TemplateName property of the Entity Template<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Template"."TemplateName"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 200<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.String TemplateName
		{
			get { return (System.String)GetValue((int)TemplateFieldIndex.TemplateName, true); }
			set	{ SetValue((int)TemplateFieldIndex.TemplateName, value, true); }
		}
		/// <summary> The TemplateSubject property of the Entity Template<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Template"."TemplateSubject"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 200<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.String TemplateSubject
		{
			get { return (System.String)GetValue((int)TemplateFieldIndex.TemplateSubject, true); }
			set	{ SetValue((int)TemplateFieldIndex.TemplateSubject, value, true); }
		}
		/// <summary> The TemplateContent property of the Entity Template<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Template"."TemplateContent"<br/>
		/// Table field type characteristics (type, precision, scale, length): NText, 0, 0, 1073741823<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.String TemplateContent
		{
			get { return (System.String)GetValue((int)TemplateFieldIndex.TemplateContent, true); }
			set	{ SetValue((int)TemplateFieldIndex.TemplateContent, value, true); }
		}
		/// <summary> The Remark property of the Entity Template<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Template"."Remark"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 500<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual System.String Remark
		{
			get { return (System.String)GetValue((int)TemplateFieldIndex.Remark, true); }
			set	{ SetValue((int)TemplateFieldIndex.Remark, value, true); }
		}
		/// <summary> The CreateDate property of the Entity Template<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Template"."CreateDate"<br/>
		/// Table field type characteristics (type, precision, scale, length): DateTime, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.DateTime CreateDate
		{
			get { return (System.DateTime)GetValue((int)TemplateFieldIndex.CreateDate, true); }
			set	{ SetValue((int)TemplateFieldIndex.CreateDate, value, true); }
		}
		/// <summary> The TargetUrl property of the Entity Template<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Template"."TargetUrl"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 200<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual System.String TargetUrl
		{
			get { return (System.String)GetValue((int)TemplateFieldIndex.TargetUrl, true); }
			set	{ SetValue((int)TemplateFieldIndex.TargetUrl, value, true); }
		}
		/// <summary> The Added property of the Entity Template<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Template"."Added"<br/>
		/// Table field type characteristics (type, precision, scale, length): Bit, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.Boolean Added
		{
			get { return (System.Boolean)GetValue((int)TemplateFieldIndex.Added, true); }
			set	{ SetValue((int)TemplateFieldIndex.Added, value, true); }
		}
		/// <summary> The Changes property of the Entity Template<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Template"."Changes"<br/>
		/// Table field type characteristics (type, precision, scale, length): Bit, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.Boolean Changes
		{
			get { return (System.Boolean)GetValue((int)TemplateFieldIndex.Changes, true); }
			set	{ SetValue((int)TemplateFieldIndex.Changes, value, true); }
		}
		/// <summary> The Remove property of the Entity Template<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Template"."Remove"<br/>
		/// Table field type characteristics (type, precision, scale, length): Bit, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.Boolean Remove
		{
			get { return (System.Boolean)GetValue((int)TemplateFieldIndex.Remove, true); }
			set	{ SetValue((int)TemplateFieldIndex.Remove, value, true); }
		}
		/// <summary> The Printing property of the Entity Template<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Template"."Printing"<br/>
		/// Table field type characteristics (type, precision, scale, length): Bit, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.Boolean Printing
		{
			get { return (System.Boolean)GetValue((int)TemplateFieldIndex.Printing, true); }
			set	{ SetValue((int)TemplateFieldIndex.Printing, value, true); }
		}
		/// <summary> The Export property of the Entity Template<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Template"."Export"<br/>
		/// Table field type characteristics (type, precision, scale, length): Bit, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.Boolean Export
		{
			get { return (System.Boolean)GetValue((int)TemplateFieldIndex.Export, true); }
			set	{ SetValue((int)TemplateFieldIndex.Export, value, true); }
		}
		/// <summary> The ToConfirm property of the Entity Template<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Template"."ToConfirm"<br/>
		/// Table field type characteristics (type, precision, scale, length): Bit, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.Boolean ToConfirm
		{
			get { return (System.Boolean)GetValue((int)TemplateFieldIndex.ToConfirm, true); }
			set	{ SetValue((int)TemplateFieldIndex.ToConfirm, value, true); }
		}

		/// <summary> Retrieves all related entities of type 'MessageEntity' using a relation of type '1:n'.</summary>
		/// <remarks>This property is added for databinding conveniance, however it is recommeded to use the method 'GetMultiMessage()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the same scope.</remarks>
		public virtual CARMSData.CollectionClasses.MessageCollection Message
		{
			get	{ return GetMultiMessage(false); }
		}

		/// <summary> Gets / sets the lazy loading flag for Message. When set to true, Message is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time Message is accessed. You can always execute
		/// a forced fetch by calling GetMultiMessage(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchMessage
		{
			get	{ return _alwaysFetchMessage; }
			set	{ _alwaysFetchMessage = value; }	
		}		
				
		/// <summary>Gets / Sets the lazy loading flag if the property Message already has been fetched. Setting this property to false when Message has been fetched
		/// will clear the Message collection well. Setting this property to true while Message hasn't been fetched disables lazy loading for Message</summary>
		[Browsable(false)]
		public bool AlreadyFetchedMessage
		{
			get { return _alreadyFetchedMessage;}
			set 
			{
				if(_alreadyFetchedMessage && !value && (_message != null))
				{
					_message.Clear();
				}
				_alreadyFetchedMessage = value;
			}
		}
		/// <summary> Retrieves all related entities of type 'ReportCategoryToTemplateEntity' using a relation of type '1:n'.</summary>
		/// <remarks>This property is added for databinding conveniance, however it is recommeded to use the method 'GetMultiReportCategoryToTemplate()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the same scope.</remarks>
		public virtual CARMSData.CollectionClasses.ReportCategoryToTemplateCollection ReportCategoryToTemplate
		{
			get	{ return GetMultiReportCategoryToTemplate(false); }
		}

		/// <summary> Gets / sets the lazy loading flag for ReportCategoryToTemplate. When set to true, ReportCategoryToTemplate is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time ReportCategoryToTemplate is accessed. You can always execute
		/// a forced fetch by calling GetMultiReportCategoryToTemplate(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchReportCategoryToTemplate
		{
			get	{ return _alwaysFetchReportCategoryToTemplate; }
			set	{ _alwaysFetchReportCategoryToTemplate = value; }	
		}		
				
		/// <summary>Gets / Sets the lazy loading flag if the property ReportCategoryToTemplate already has been fetched. Setting this property to false when ReportCategoryToTemplate has been fetched
		/// will clear the ReportCategoryToTemplate collection well. Setting this property to true while ReportCategoryToTemplate hasn't been fetched disables lazy loading for ReportCategoryToTemplate</summary>
		[Browsable(false)]
		public bool AlreadyFetchedReportCategoryToTemplate
		{
			get { return _alreadyFetchedReportCategoryToTemplate;}
			set 
			{
				if(_alreadyFetchedReportCategoryToTemplate && !value && (_reportCategoryToTemplate != null))
				{
					_reportCategoryToTemplate.Clear();
				}
				_alreadyFetchedReportCategoryToTemplate = value;
			}
		}
		/// <summary> Retrieves all related entities of type 'TemplateToReportCategoryEntity' using a relation of type '1:n'.</summary>
		/// <remarks>This property is added for databinding conveniance, however it is recommeded to use the method 'GetMultiTemplateToReportCategory()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the same scope.</remarks>
		public virtual CARMSData.CollectionClasses.TemplateToReportCategoryCollection TemplateToReportCategory
		{
			get	{ return GetMultiTemplateToReportCategory(false); }
		}

		/// <summary> Gets / sets the lazy loading flag for TemplateToReportCategory. When set to true, TemplateToReportCategory is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time TemplateToReportCategory is accessed. You can always execute
		/// a forced fetch by calling GetMultiTemplateToReportCategory(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchTemplateToReportCategory
		{
			get	{ return _alwaysFetchTemplateToReportCategory; }
			set	{ _alwaysFetchTemplateToReportCategory = value; }	
		}		
				
		/// <summary>Gets / Sets the lazy loading flag if the property TemplateToReportCategory already has been fetched. Setting this property to false when TemplateToReportCategory has been fetched
		/// will clear the TemplateToReportCategory collection well. Setting this property to true while TemplateToReportCategory hasn't been fetched disables lazy loading for TemplateToReportCategory</summary>
		[Browsable(false)]
		public bool AlreadyFetchedTemplateToReportCategory
		{
			get { return _alreadyFetchedTemplateToReportCategory;}
			set 
			{
				if(_alreadyFetchedTemplateToReportCategory && !value && (_templateToReportCategory != null))
				{
					_templateToReportCategory.Clear();
				}
				_alreadyFetchedTemplateToReportCategory = value;
			}
		}

		/// <summary> Retrieves all related entities of type 'ReportCategoryEntity' using a relation of type 'm:n'.</summary>
		/// <remarks>This property is added for databinding conveniance, however it is recommeded to use the method 'GetMultiReportCategoryCollectionViaReportCategoryToTemplate()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the same scope.</remarks>
		public virtual CARMSData.CollectionClasses.ReportCategoryCollection ReportCategoryCollectionViaReportCategoryToTemplate
		{
			get { return GetMultiReportCategoryCollectionViaReportCategoryToTemplate(false); }
		}

		/// <summary> Gets / sets the lazy loading flag for ReportCategoryCollectionViaReportCategoryToTemplate. When set to true, ReportCategoryCollectionViaReportCategoryToTemplate is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time ReportCategoryCollectionViaReportCategoryToTemplate is accessed. You can always execute
		/// a forced fetch by calling GetMultiReportCategoryCollectionViaReportCategoryToTemplate(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchReportCategoryCollectionViaReportCategoryToTemplate
		{
			get	{ return _alwaysFetchReportCategoryCollectionViaReportCategoryToTemplate; }
			set	{ _alwaysFetchReportCategoryCollectionViaReportCategoryToTemplate = value; }
		}
				
		/// <summary>Gets / Sets the lazy loading flag if the property ReportCategoryCollectionViaReportCategoryToTemplate already has been fetched. Setting this property to false when ReportCategoryCollectionViaReportCategoryToTemplate has been fetched
		/// will clear the ReportCategoryCollectionViaReportCategoryToTemplate collection well. Setting this property to true while ReportCategoryCollectionViaReportCategoryToTemplate hasn't been fetched disables lazy loading for ReportCategoryCollectionViaReportCategoryToTemplate</summary>
		[Browsable(false)]
		public bool AlreadyFetchedReportCategoryCollectionViaReportCategoryToTemplate
		{
			get { return _alreadyFetchedReportCategoryCollectionViaReportCategoryToTemplate;}
			set 
			{
				if(_alreadyFetchedReportCategoryCollectionViaReportCategoryToTemplate && !value && (_reportCategoryCollectionViaReportCategoryToTemplate != null))
				{
					_reportCategoryCollectionViaReportCategoryToTemplate.Clear();
				}
				_alreadyFetchedReportCategoryCollectionViaReportCategoryToTemplate = value;
			}
		}
		/// <summary> Retrieves all related entities of type 'ReportCategoryEntity' using a relation of type 'm:n'.</summary>
		/// <remarks>This property is added for databinding conveniance, however it is recommeded to use the method 'GetMultiReportCategoryCollectionViaTemplateToReportCategory()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the same scope.</remarks>
		public virtual CARMSData.CollectionClasses.ReportCategoryCollection ReportCategoryCollectionViaTemplateToReportCategory
		{
			get { return GetMultiReportCategoryCollectionViaTemplateToReportCategory(false); }
		}

		/// <summary> Gets / sets the lazy loading flag for ReportCategoryCollectionViaTemplateToReportCategory. When set to true, ReportCategoryCollectionViaTemplateToReportCategory is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time ReportCategoryCollectionViaTemplateToReportCategory is accessed. You can always execute
		/// a forced fetch by calling GetMultiReportCategoryCollectionViaTemplateToReportCategory(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchReportCategoryCollectionViaTemplateToReportCategory
		{
			get	{ return _alwaysFetchReportCategoryCollectionViaTemplateToReportCategory; }
			set	{ _alwaysFetchReportCategoryCollectionViaTemplateToReportCategory = value; }
		}
				
		/// <summary>Gets / Sets the lazy loading flag if the property ReportCategoryCollectionViaTemplateToReportCategory already has been fetched. Setting this property to false when ReportCategoryCollectionViaTemplateToReportCategory has been fetched
		/// will clear the ReportCategoryCollectionViaTemplateToReportCategory collection well. Setting this property to true while ReportCategoryCollectionViaTemplateToReportCategory hasn't been fetched disables lazy loading for ReportCategoryCollectionViaTemplateToReportCategory</summary>
		[Browsable(false)]
		public bool AlreadyFetchedReportCategoryCollectionViaTemplateToReportCategory
		{
			get { return _alreadyFetchedReportCategoryCollectionViaTemplateToReportCategory;}
			set 
			{
				if(_alreadyFetchedReportCategoryCollectionViaTemplateToReportCategory && !value && (_reportCategoryCollectionViaTemplateToReportCategory != null))
				{
					_reportCategoryCollectionViaTemplateToReportCategory.Clear();
				}
				_alreadyFetchedReportCategoryCollectionViaTemplateToReportCategory = value;
			}
		}
		/// <summary> Retrieves all related entities of type 'ReportHeaderEntity' using a relation of type 'm:n'.</summary>
		/// <remarks>This property is added for databinding conveniance, however it is recommeded to use the method 'GetMultiReportHeaderCollectionViaMessage()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the same scope.</remarks>
		public virtual CARMSData.CollectionClasses.ReportHeaderCollection ReportHeaderCollectionViaMessage
		{
			get { return GetMultiReportHeaderCollectionViaMessage(false); }
		}

		/// <summary> Gets / sets the lazy loading flag for ReportHeaderCollectionViaMessage. When set to true, ReportHeaderCollectionViaMessage is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time ReportHeaderCollectionViaMessage is accessed. You can always execute
		/// a forced fetch by calling GetMultiReportHeaderCollectionViaMessage(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchReportHeaderCollectionViaMessage
		{
			get	{ return _alwaysFetchReportHeaderCollectionViaMessage; }
			set	{ _alwaysFetchReportHeaderCollectionViaMessage = value; }
		}
				
		/// <summary>Gets / Sets the lazy loading flag if the property ReportHeaderCollectionViaMessage already has been fetched. Setting this property to false when ReportHeaderCollectionViaMessage has been fetched
		/// will clear the ReportHeaderCollectionViaMessage collection well. Setting this property to true while ReportHeaderCollectionViaMessage hasn't been fetched disables lazy loading for ReportHeaderCollectionViaMessage</summary>
		[Browsable(false)]
		public bool AlreadyFetchedReportHeaderCollectionViaMessage
		{
			get { return _alreadyFetchedReportHeaderCollectionViaMessage;}
			set 
			{
				if(_alreadyFetchedReportHeaderCollectionViaMessage && !value && (_reportHeaderCollectionViaMessage != null))
				{
					_reportHeaderCollectionViaMessage.Clear();
				}
				_alreadyFetchedReportHeaderCollectionViaMessage = value;
			}
		}
		/// <summary> Retrieves all related entities of type 'UserEntity' using a relation of type 'm:n'.</summary>
		/// <remarks>This property is added for databinding conveniance, however it is recommeded to use the method 'GetMultiUserCollectionViaMessage()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the same scope.</remarks>
		public virtual CARMSData.CollectionClasses.UserCollection UserCollectionViaMessage
		{
			get { return GetMultiUserCollectionViaMessage(false); }
		}

		/// <summary> Gets / sets the lazy loading flag for UserCollectionViaMessage. When set to true, UserCollectionViaMessage is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time UserCollectionViaMessage is accessed. You can always execute
		/// a forced fetch by calling GetMultiUserCollectionViaMessage(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchUserCollectionViaMessage
		{
			get	{ return _alwaysFetchUserCollectionViaMessage; }
			set	{ _alwaysFetchUserCollectionViaMessage = value; }
		}
				
		/// <summary>Gets / Sets the lazy loading flag if the property UserCollectionViaMessage already has been fetched. Setting this property to false when UserCollectionViaMessage has been fetched
		/// will clear the UserCollectionViaMessage collection well. Setting this property to true while UserCollectionViaMessage hasn't been fetched disables lazy loading for UserCollectionViaMessage</summary>
		[Browsable(false)]
		public bool AlreadyFetchedUserCollectionViaMessage
		{
			get { return _alreadyFetchedUserCollectionViaMessage;}
			set 
			{
				if(_alreadyFetchedUserCollectionViaMessage && !value && (_userCollectionViaMessage != null))
				{
					_userCollectionViaMessage.Clear();
				}
				_alreadyFetchedUserCollectionViaMessage = value;
			}
		}

		/// <summary> Gets / sets related entity of type 'ActionEntity'. This property is not visible in databound grids.
		/// Setting this property to a new object will make the load-on-demand feature to stop fetching data from the database, until you set this
		/// property to null. Setting this property to an entity will make sure that FK-PK relations are synchronized when appropriate.</summary>
		/// <remarks>This property is added for conveniance, however it is recommeded to use the method 'GetSingleAction()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the
		/// same scope. The property is marked non-browsable to make it hidden in bound controls, f.e. datagrids.</remarks>
		[Browsable(false)]
		public virtual ActionEntity Action
		{
			get	{ return GetSingleAction(false); }
			set
			{
				if(base.IsDeserializing)
				{
					SetupSyncAction(value);
				}
				else
				{
					if(value==null)
					{
						if(_action != null)
						{
							_action.UnsetRelatedEntity(this, "Template");
						}
					}
					else
					{
						if(_action!=value)
						{
							((IEntity)value).SetRelatedEntity(this, "Template");
						}
					}
				}
			}
		}

		/// <summary> Gets / sets the lazy loading flag for Action. When set to true, Action is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time Action is accessed. You can always execute
		/// a forced fetch by calling GetSingleAction(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchAction
		{
			get	{ return _alwaysFetchAction; }
			set	{ _alwaysFetchAction = value; }	
		}
				
		/// <summary>Gets / Sets the lazy loading flag if the property Action already has been fetched. Setting this property to false when Action has been fetched
		/// will set Action to null as well. Setting this property to true while Action hasn't been fetched disables lazy loading for Action</summary>
		[Browsable(false)]
		public bool AlreadyFetchedAction
		{
			get { return _alreadyFetchedAction;}
			set 
			{
				if(_alreadyFetchedAction && !value)
				{
					this.Action = null;
				}
				_alreadyFetchedAction = value;
			}
		}

		/// <summary> Gets / sets the flag for what to do if the related entity available through the property Action is not found
		/// in the database. When set to true, Action will return a new entity instance if the related entity is not found, otherwise 
		/// null be returned if the related entity is not found. Default: true.</summary>
		[Browsable(false)]
		public bool ActionReturnsNewIfNotFound
		{
			get	{ return _actionReturnsNewIfNotFound; }
			set { _actionReturnsNewIfNotFound = value; }	
		}



		/// <summary> Gets or sets a value indicating whether this entity is a subtype</summary>
		protected override bool LLBLGenProIsSubType
		{
			get { return false;}
		}

		/// <summary> Gets the type of the hierarchy this entity is in. </summary>
		[System.ComponentModel.Browsable(false), XmlIgnore]
		protected override InheritanceHierarchyType LLBLGenProIsInHierarchyOfType
		{
			get { return InheritanceHierarchyType.None;}
		}
		
		/// <summary>Returns the CARMSData.EntityType enum value for this entity.</summary>
		[Browsable(false), XmlIgnore]
		public override int LLBLGenProEntityTypeValue 
		{ 
			get { return (int)CARMSData.EntityType.TemplateEntity; }
		}
		#endregion


		#region Custom Entity code
		
		// __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode
		// __LLBLGENPRO_USER_CODE_REGION_END
		#endregion

		#region Included code

		#endregion
	}
}
